#ifndef __STRUTL_H_INCLUDE__
#define __STRUTL_H_INCLUDE__

#include <sysdep.h>

typedef struct _string_map_t {
	const char *name;
	int number;
} string_map_t;

const char *sock_errstr(void);

#define STR_MAX_INADDR	16

/* Little func */
#ifndef MAKEBOOL01
#define MAKEBOOL01(value) ((value) ? 1 : 0)
#endif

/* This string operations file use for dictionary file */
#define STROP_MAX_BUF_LEN	512
#define MAX_WORD_LENGTH		STROP_MAX_BUF_LEN		

int file_get_line(int fd, char *buf);
int gbk2utf8(unsigned char * gdkstr,unsigned char * utf8str,int utf8len);
int utf82gbk(unsigned char *lpUTF8Str, unsigned char *lpGBKStr,int nGBKStrLen);
int code_convert(char *from_charset,char *to_charset, char *inbuf,
		 int inlen, char *outbuf, int outlen);

const char *u8tostr(uint16_t num);
const char *u16tostr(uint16_t num);
uint8_t str2u8(const char *str);
uint16_t str2u16(const char *str);

char *time_string(int utc, time_t tm);
int hex2i(const char *hex);
uint8_t hexchar(char h);

void chomp(char *line);
size_t strlcpy(char *dst, const char *src, size_t size);
size_t strlcat(char *dst, const char *src, size_t size);
size_t strnlen(const char *s, size_t count);
char *strrcat(char *old_str, const char *str);

int vslprintf(char *buf, int buflen, const char *fmt, va_list args);
int slprintf(char *buf, int buflen, const char *fmt, ...);

#ifdef WIN32
uint64_t strtoull(const char *, char **, unsigned int);
#endif
void strupper(char *string);

int replace_chars(char *str, const char *white);
int utf8_encoded_valid_unichar(const char *str);
size_t path_decode(char *s);
size_t path_encode(char *s, size_t len);
void remove_trailing_chars(char *path, char c);
int string_is_true(const char *str);

int str2int(const string_map_t *table, const char *name, int def);
const char *int2str(const string_map_t *table, int number, const char *def);

void do_percentm(char *obuf, const char *ibuf);

void daemonize(void);

int reverse_bits(int orig_bits, int n);
char *str_convert_char(char *s, char from, char to);

#endif /* __STRUTL_H_INCLUDE__ */

